<?php
class paperprint
{
    var $ConfTplArray=array(
            'order_id' => '[订单号]',
            'order_id_barcode' => '[订单条码]',
            'order_type' => '[订单类型]',
            'create_time' => '[下单时间]',//
            'ship_time' => '[发货时间]',
            'ship_date' => '[发货日期]',//
            'count' => '[产品件数]',//
            'sum' => '[订单金额]',
            
            'ship_name' => '[收件人]',
            'ship_mobile' => '[收件电话]',
            'ship_zip' => '[收件邮编]',
            'ship_comp' => '[收件单位]',
            'ship_addr' => '[发往地址]',
            'shipping_no_barcode' => '[运单号条码]',
            
            'sender_name' => '[发件人]',
            'sender_phone' => '[发件电话]',
            'sender_comp' => '[发件单位]',
            'sender_addr' => '[发件地址]',
            'sender_zip' => '[发件邮编]',
            
            'payment_name' => '[支付方式]',
            'shipping_name' => '[配送方式]',
            'express_num' => '[快递单号]',
            'freight' => '[配送费]',
            'shipping_weight' => '[计费重量]',
            'return_decimal_price' => '[保价金额]',
            'picking_goods_info' => '[配货信息]',

            'invoices_type' => '[发票信息]',
            'invoices_content' => '[发票抬头]',
            'invoices_rise' => '[发票内容]',
            
            'goods_type' => '[货品类型]',
            'other' => '[备注]',
    		'name' => '[名称]',
    		'writer_date' => '[填写时间]',
    		'shop' => '[仓库]',
    		'supplier' => '[供应商]',
    		'puser' => '[填写人]',
    		'total_price' => '[总价]',
    		'purchase_no' => '[采购单编号]',
    		'purchase_express_money' => '[采购运费]',
    		'purchase_discount_money' => '[采购折扣]',
    		'purchase_other_money' => '[其他采购费]',
    		'purchase_total_money' => '[采购总价]',
    		'currency_unit' => '[货币单位]',
            
            'goods' => array(
                    'name' => '[货品名称]',
            		'id'=>'[货品ID]',
            		'barcode'=>'[货品条码]',
            		'cat_name'=>'[货品品类]',
            		'code'=>'[货品编码]',
            		'spec'=>'[货品规格]',
            		'unit'=>'[货品单位]',
                    'num' => '[货品数量]',
                    'price' => '[货品单价]',
                    'sum' => '[货品小计]',
                    'other' => '[货品备注]',
            		'pic' => '[货品图片]'
            )
    );
    
    function __construct(){}

    function sendprint(&$oinfo,&$sendtpl)
    {
        $ConfTplArray=$this->ConfTplArray;
        foreach ( $oinfo as $k => $v ) {
            if (! $ConfTplArray [$k])
                continue;
            $strstr [$ConfTplArray [$k]] = $v;
        }
        $reg = "/<([a-z]+)\s+id=\"\[货品\]\">(.*?)<\/\\1>/is";
        $reg2 = "/<([a-z]+)\s+id=\"\[商品\]\">(.*?)<\/\\1>/is";
        preg_match_all ( $reg, $sendtpl, $out );
        preg_match_all ( $reg2, $sendtpl, $out2 );
        if ($good=$oinfo['product']) {
            foreach ( $good as $k => $v ) {
            	if($v['is_stocked']>=0){
	                foreach ( $v as $key => $value ) {
	                    if (! $ConfTplArray ['goods'] [$key])
	                        continue;
	                    $goodstr [$ConfTplArray ['goods'] [$key]] = $value;
	                    $goodstr ['[货品序号]'] = $k + 1;
	                }
	                $goods [] = strtr ( $out [0] [0], $goodstr );
	                $goods2 [] = strtr ( $out2 [0] [0], $goodstr );
            	}
            }
        }
        $sendtpl = preg_replace ( $reg, @implode ( "", $goods ), $sendtpl );
        $sendtpl = preg_replace ( $reg2, @implode ( "", $goods2 ), $sendtpl );
        
        return  strtr ($sendtpl, $strstr ); 
    }
    function expressprint(&$oinfo,&$expresstpl)
    {
        $ConfTplArray=$this->ConfTplArray;
        foreach ( $oinfo as $k => $v ) {
            if (! $ConfTplArray [$k])
                continue;
            $strstr [$ConfTplArray [$k]] = $v;
        }
        return  strtr ($expresstpl, $strstr );
    }
}
    
    
    
    